"""
orderedMap
Map就是数据结构中的map 指key-value对
ordered指对key进行排序了

python3.6之后的dict都是有序的 都是orderedMap
python中常用的orderedMap还有collections.Counter

下面是例题leetcode.cn 846
"""

class Solution:
    def isNStraightHand(self, hand: List[int], W: int) -> bool:
        n = len(hand)
        if n%W!=0:
            return False
        
        count = collections.Counter(hand)
        
        while count:
            m = min(count) #根据key选择的最小值
            
            min_n = sys.maxsize
            for i in range(m, m+W):
                if i not in count:
                    return False
                else:
                    min_n = min(min_n, count[i])
            
            for i in range(m, m+W):
                if count[i] == min_n:
                    del count[i]
                else:
                    count[i] -= min_n
        return True